package top.minuy.subject.leetcode._349;

import java.util.ArrayList;
import java.util.TreeSet;
/**
 * @author Minuy
 * @time 12:17
 * @date 2021/9/12
 */
public class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        TreeSet<Integer> set = new TreeSet<>();
        for (int i:nums1) {
            set.add(i);
        }

        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i:nums2) {
            if(set.contains(i)){
                arrayList.add(i);
                set.remove(i);
            }
        }

        int[] res = new int[arrayList.size()];

        for (int i=0;i<arrayList.size();i++){
            res[i] = arrayList.get(i);
        }

        return res;
    }
}
